package dk.vighdata.slzapp;
import java.util.Calendar;
/**
 * Created by fuke9_000 on 02-03-2015.
 */
public class LanCounter {
    private Calendar cal = Calendar.getInstance();
    private Calendar lanDate = Calendar.getInstance();
    private long today;
    private long lanDay;

    /**
     * Constructor for LanCounter.
     * @param year the year of next LAN
     * @param month the month of next LAN
     * @param day the day in the month of next LAN
     */
    public LanCounter(int year, int month, int day) {
        lanDate.set(year, month-1, day, 12, 00, 00); //month-1 because month index starts at 0
    }

    /**
     * Ensuring that today and lanDay are assigned correctly
     */
    private void setTime() {
        today = cal.getTime().getTime();
        lanDay = lanDate.getTime().getTime();
    }

    public long getMillisToLan() {
        setTime();
        return lanDay - today;
    }

    public long getSecondsToLan() {
        return getMillisToLan()/1000;
    }

    public long getMinutesToLan() {
        return getSecondsToLan()/60;
    }

    public long getHoursToLan() {
        return getMinutesToLan()/60;
    }

    public long getDaysToLan() {
        return getHoursToLan()/24;
    }

    public long getWeeksToLan() {
        return getDaysToLan()/7;
    }

    public long getDaysAfterWeeks() {
        long seconds = getSecondsToLan();
        long weeksInSeconds = getWeeksToLan()*60*60*24*7;
        long restDaysInSeconds = seconds-weeksInSeconds;
        return restDaysInSeconds/60/60/24;
    }

    public long getHoursAfterDays() {
        long seconds = getSecondsToLan();
        long daysInSeconds = getDaysToLan()*60*60*24;
        long restHoursInSeconds = seconds - daysInSeconds;
        return restHoursInSeconds/60/60;
    }

    public long getMinutesAfterHours() {
        long seconds = getSecondsToLan();
        long minutesInSeconds = getHoursToLan()*60*60;
        long restMinutesInSeconds = seconds - minutesInSeconds;
        return restMinutesInSeconds/60;
    }

    public long getSecondsAfterMinutes() {
        long seconds = getSecondsToLan();
        long minutesInSeconds = getMinutesToLan()*60;
        return seconds - minutesInSeconds;
    }

    public String getTimeToLanString() {
        return getWeeksToLan() + " Uger, " + getDaysAfterWeeks() + " Dage, " + getHoursAfterDays() + " Timer, " + getMinutesAfterHours() + " Minutter";
    }
}
